package com.boge.modules.shop.service.impl;

import com.boge.modules.shop.entity.CattypeEntity;
import com.boge.modules.shop.service.CattypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.Query;

import com.boge.modules.shop.dao.CatDao;
import com.boge.modules.shop.entity.CatEntity;
import com.boge.modules.shop.service.CatService;


@Service("catService")
public class CatServiceImpl extends ServiceImpl<CatDao, CatEntity> implements CatService {

    @Autowired
    private CattypeService cattypeService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CatEntity> page = this.page(
                new Query<CatEntity>().getPage(params),
                new QueryWrapper<CatEntity>()
        );

        List<CatEntity> records = page.getRecords();
        if(records != null){
            for (CatEntity record : records) {
                CattypeEntity cattypeEntity = cattypeService.getById(record.getTypeId());
                record.setTypeName(cattypeEntity.getName());
            }
        }

        return new PageUtils(page);
    }

}